﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.IO;
using DTBuilderLib;

namespace DeepTalkWF
{
    /// <summary>
    /// Sets the token file for a DZ talk directory. Usually done after a rendering has been completed.
    /// </summary>
	public partial class SetDZToken: Activity
	{
		public SetDZToken()
		{
			InitializeComponent();
		}

        /// <summary>
        /// The Deep Zoom builder directory
        /// </summary>
        public DirectoryInfo DZDirectory
        {
            get { return (DirectoryInfo)GetValue(DZDirectoryProperty); }
            set { SetValue(DZDirectoryProperty, value); }
        }

        // Using a DependencyProperty as the backing store for DZDirectory.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DZDirectoryProperty =
            DependencyProperty.Register("DZDirectory", typeof(DirectoryInfo), typeof(SetDZToken), new PropertyMetadata(null));

        /// <summary>
        /// Name the meeting is rendered against.
        /// </summary>
        public string MeetingName
        {
            get { return (string)GetValue(MeetingNameProperty); }
            set { SetValue(MeetingNameProperty, value); }
        }

        // Using a DependencyProperty as the backing store for MeetingName.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MeetingNameProperty =
            DependencyProperty.Register("MeetingName", typeof(string), typeof(SetDZToken), new PropertyMetadata(null));

        /// <summary>
        /// Make sure the file exists. Assume that the local file access is instant and
        /// requires no pausing. Not stricktly correct, of course, but lets pretend the
        /// filesystem doesn't hang on us!
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            DeepZoomBuilder bld = new DeepZoomBuilder();
            bld.BuildDirectory = DZDirectory.FullName;
            bld.SetToken(MeetingName);

            return ActivityExecutionStatus.Closed;
        }
	}
}
